package org.example.bumenguanli.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.bumenguanli.aspect.LogOperation;
import org.example.bumenguanli.pojo.*;
import org.example.bumenguanli.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;



    @GetMapping("/clazzs")
    public Result page(EmpQueryParam empQueryParam) {
        log.info("查询请求参数： {}", empQueryParam);
        PageResult pageResult = clazzService.page(empQueryParam);
        return Result.success(pageResult);
    }


    @PostMapping("/clazzs")

    public Result save(@RequestBody Clazz clazz) {
        log.info("请求参数emp: {}", clazz);
        clazzService.save(clazz);
        return Result.success();
    }

    @GetMapping("/clazzs/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工的详细信息");
        Clazz clazz  = clazzService.getInfo(id);
        return Result.success(clazz);
    }

    @PutMapping("/clazzs")
    @LogOperation
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息, {}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    @DeleteMapping("/clazzs/{id}")
    @LogOperation
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除班级信息: {}", id);
        clazzService.delete(id);
        return Result.success();
    }

    @GetMapping("/clazzs/list")
    public Result findemp(Clazz clazz) {
        log.info("根据id查询员工的详细信息");
        List<Clazz> clazzList  = clazzService.clazzlist(clazz);
        return Result.success(clazzList);
    }



}
